﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    Layout = null;

    //公式部分
    List<dynamic> 分管客户总数 = new List<dynamic>();
    List<dynamic> 分管客户变化量 = new List<dynamic>();
    List<dynamic> 隐性流失客户数 = new List<dynamic>();
    
    List<dynamic> 招徕实施率 = new List<dynamic>();
    List<dynamic> 预约成功率 = new List<dynamic>();
    List<dynamic> 准时交车率 = new List<dynamic>();

    List<dynamic> 招徕实施率1 = new List<dynamic>();
    List<dynamic> 事实流失率 = new List<dynamic>();
    List<dynamic> 隐性流失率 = new List<dynamic>();
    
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {
        var 当月考核目标 = Model.StandardConfigs.Where(o=>o.Month.Year==dt.Year && o.Month.Month==dt.Month).FirstOrDefault();
        var 月初数据 = Model.MonthTargets.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month).FirstOrDefault();
        var 每日数据 = Model.SADayDatas.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month);
        if(当月考核目标==null)
        {
            当月考核目标 =  new  S4Store.Domain.AfterSaleKpi.MonthStandardConfig();
        }
        
        if(月初数据==null)
        {
            月初数据 = new S4Store.Domain.AfterSaleKpi.AfterSaleServiceAdvisorMonthTarget();
        }

        分管客户总数.Add(new
        {
            时间 = dt,
            客户总数 = 月初数据.SYMFGKHZS_LastMonthManageCustomerNum
        });

        分管客户变化量.Add(new
        {
            时间 = dt,
            本月新增流失客户数 = 每日数据.Sum(o => o.XZLGYWHCS),
            本月A卡转C卡数 = 每日数据.Sum(o=>o.BYAKZCKKHS_ACard2CCard),
        });

        隐性流失客户数.Add(new
        {
            时间 = dt,
            隐性流失客户数 = 每日数据.Sum(o => o.XZSGYWHCS)
        });

        招徕实施率.Add(new
        {
            时间 = dt,
            招徕实施率目标 = 当月考核目标.招徕实施率目标,
            招徕实施率实际 = Model.GetZLSSL(月初数据.EmployeeId, dt.Year, dt.Month)
        });

        预约成功率.Add(new
        {
            时间 = dt,
            预约成功率目标 = 当月考核目标.预约成功率目标,
            预约成功率实际 = Model.GetYYCGL(月初数据.EmployeeId, dt.Year, dt.Month)
        });

        准时交车率.Add(new
        {
            时间 = dt,
            准时交车率目标 = 当月考核目标.准时交车率目标,
            准时交车率实际 = Model.GetSAZSJCL(月初数据.EmployeeId, dt.Year, dt.Month)
        });

        招徕实施率1.Add(new
        {
            时间 = dt,
            招徕实施率目标 = 当月考核目标.招徕实施率目标,
            招徕实施率实际 = Model.GetZLSSL(月初数据.EmployeeId, dt.Year, dt.Month)
        });

        事实流失率.Add(new
        {
            时间 = dt,
            事实流失率目标 = 当月考核目标.事实流失率目标,
            事实流失率实际 = Model.GetSSKHLSL(月初数据.EmployeeId, dt.Year, dt.Month)
        });

        隐性流失率.Add(new
        {
            时间 = dt,
            隐性流失率目标 = 当月考核目标.隐形流失率目标,
            隐性流失率实际 = Model.GetYXLSL(月初数据.EmployeeId, dt.Year, dt.Month)
        });
    }
    
    //图标部分
    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.IsRate = false;
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.YAxis = "分管客户总数";

    foreach (var item in 分管客户总数.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "分管客户总数";
    foreach (var item in 分管客户总数)
    {
        series.Data.Add(item.客户总数);
    }
    ChartModel.Serieses.Add(series);
   


    //2
    S4Store.Models.Chart.Line ChartModel1 = new S4Store.Models.Chart.Line();
    ChartModel1.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel1.IsRate = false;
    ChartModel1.YAxis = "分管客户变化量";

    foreach (var item in 分管客户变化量.GroupBy(o => o.时间))
    {
        ChartModel1.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }

    S4Store.Models.Chart.ChartSeries series11 = new S4Store.Models.Chart.ChartSeries();
    series11.Name = "本月新增流失客户数";
    foreach (var item in 分管客户变化量)
    {
        series11.Data.Add(item.本月新增流失客户数);
    }
    ChartModel1.Serieses.Add(series11);

    S4Store.Models.Chart.ChartSeries series12 = new S4Store.Models.Chart.ChartSeries();
    series12.Name = "本月A卡转C卡数";
    foreach (var item in 分管客户变化量)
    {
        series12.Data.Add(item.本月A卡转C卡数);
    }
    ChartModel1.Serieses.Add(series12);

    
    
    //3
    S4Store.Models.Chart.Line ChartModel3 = new S4Store.Models.Chart.Line();
    ChartModel3.IsRate = false;
    ChartModel3.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel3.YAxis = "隐性流失客户数";

    foreach (var item in 隐性流失客户数.GroupBy(o => o.时间))
    {
        ChartModel3.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series31 = new S4Store.Models.Chart.ChartSeries();
    series31.Name = "隐性流失客户数";
    foreach (var item in 隐性流失客户数)
    {
        series31.Data.Add(item.隐性流失客户数);
    }
    ChartModel3.Serieses.Add(series31);
    
    
    //TAB2
    //图标部分
    S4Store.Models.Chart.Line ChartModelT2 = new S4Store.Models.Chart.Line();
    ChartModelT2.IsRate = true;
    ChartModelT2.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModelT2.YAxis = "招徕实施率";

    foreach (var item in 招徕实施率.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries seriesT2 = new S4Store.Models.Chart.ChartSeries();
    seriesT2.Name = "招徕实施率目标";
    foreach (var item in 招徕实施率)
    {
        seriesT2.Data.Add(item.招徕实施率目标);
    }
    ChartModelT2.Serieses.Add(seriesT2);
    S4Store.Models.Chart.ChartSeries seriesT21 = new S4Store.Models.Chart.ChartSeries();
    seriesT21.Name = "招徕实施率实际";
    foreach (var item in 招徕实施率)
    {
        seriesT21.Data.Add(item.招徕实施率实际);
    }
    ChartModel.Serieses.Add(seriesT21);



    //2
    S4Store.Models.Chart.Line ChartModel1T2 = new S4Store.Models.Chart.Line();
    ChartModel1T2.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel1T2.IsRate = true;
    ChartModel1T2.YAxis = "预约成功率";

    foreach (var item in 预约成功率.GroupBy(o => o.时间))
    {
        ChartModel1T2.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }

    S4Store.Models.Chart.ChartSeries series11T2 = new S4Store.Models.Chart.ChartSeries();
    series11T2.Name = "预约成功率目标";
    foreach (var item in 预约成功率)
    {
        series11T2.Data.Add(item.预约成功率目标);
    }
    ChartModel1T2.Serieses.Add(series11T2);

    S4Store.Models.Chart.ChartSeries series12T2 = new S4Store.Models.Chart.ChartSeries();
    series12T2.Name = "预约成功率实际";
    foreach (var item in 预约成功率)
    {
        series12T2.Data.Add(item.预约成功率实际);
    }
    ChartModel1T2.Serieses.Add(series12T2);



    //3
    S4Store.Models.Chart.Line ChartModel3T2 = new S4Store.Models.Chart.Line();
    ChartModel3T2.IsRate = true;
    ChartModel3T2.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel3T2.YAxis = "准时交车率";

    foreach (var item in 准时交车率.GroupBy(o => o.时间))
    {
        ChartModel3T2.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series31T2 = new S4Store.Models.Chart.ChartSeries();
    series31T2.Name = "准时交车率目标";
    foreach (var item in 准时交车率)
    {
        series31T2.Data.Add(item.准时交车率目标);
    }
    ChartModel3T2.Serieses.Add(series31T2);

    S4Store.Models.Chart.ChartSeries series32T2 = new S4Store.Models.Chart.ChartSeries();
    series32T2.Name = "准时交车率实际";
    foreach (var item in 准时交车率)
    {
        series32T2.Data.Add(item.准时交车率实际);
    }
    ChartModel3T2.Serieses.Add(series32T2);
    
    //TAB3
    //图标部分
    S4Store.Models.Chart.Line ChartModelT3 = new S4Store.Models.Chart.Line();
    ChartModelT3.IsRate = true;
    ChartModelT3.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModelT3.YAxis = "满意度得分";

    foreach (var item in 招徕实施率1.GroupBy(o => o.时间))
    {
        ChartModelT3.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries seriesT3 = new S4Store.Models.Chart.ChartSeries();
    seriesT3.Name = "招徕实施率目标";
    foreach (var item in 招徕实施率1)
    {
        seriesT3.Data.Add(item.招徕实施率目标);
    }
    ChartModelT3.Serieses.Add(seriesT3);
    S4Store.Models.Chart.ChartSeries series1T3 = new S4Store.Models.Chart.ChartSeries();
    series1T3.Name = "招徕实施率实际";
    foreach (var item in 招徕实施率1)
    {
        series1T3.Data.Add(item.招徕实施率实际);
    }
    ChartModelT3.Serieses.Add(series1T3);



    //2
    S4Store.Models.Chart.Line ChartModel1T3 = new S4Store.Models.Chart.Line();
    ChartModel1T3.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel1T3.IsRate = true;
    ChartModel1T3.YAxis = "客户流失率";

    foreach (var item in 事实流失率.GroupBy(o => o.时间))
    {
        ChartModel1T3.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }

    S4Store.Models.Chart.ChartSeries series11T3 = new S4Store.Models.Chart.ChartSeries();
    series11T3.Name = "客户流失率目标";
    foreach (var item in 事实流失率)
    {
        series11T3.Data.Add(item.事实流失率目标);
    }
    ChartModel1T3.Serieses.Add(series11T3);

    S4Store.Models.Chart.ChartSeries series12T3 = new S4Store.Models.Chart.ChartSeries();
    series12T3.Name = "客户流失率实际";
    foreach (var item in 事实流失率)
    {
        series12T3.Data.Add(item.事实流失率实际);
    }
    ChartModel1T3.Serieses.Add(series12T3);



    //3
    S4Store.Models.Chart.Line ChartModel3T3 = new S4Store.Models.Chart.Line();
    ChartModel3T3.IsRate = true;
    ChartModel3T3.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel3T3.YAxis = "隐性流失率";

    foreach (var item in 隐性流失率.GroupBy(o => o.时间))
    {
        ChartModel3T3.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series31T3 = new S4Store.Models.Chart.ChartSeries();
    series31T3.Name = "隐性流失率目标";
    foreach (var item in 隐性流失率)
    {
        series31T3.Data.Add(item.隐性流失率目标);
    }
    ChartModel3T3.Serieses.Add(series31T3);

    S4Store.Models.Chart.ChartSeries series32T3 = new S4Store.Models.Chart.ChartSeries();
    series32T3.Name = "隐性流失率实际";
    foreach (var item in 隐性流失率)
    {
        series32T3.Data.Add(item.隐性流失率实际);
    }
    ChartModel3T3.Serieses.Add(series32T3);

}
<div style="height:100%; overflow:auto">
@Html.Action("ReportBar", "Common", Model.BarModel)
@*<div class="pagetitle">@(carbrandname)入厂台次过程KPI历史数据查询</div>*@
<div class="pageContent">
	
	<div class="tabs" currentIndex="0" eventType="none">
		<div class="tabsHeader">
			<div class="tabsHeaderContent">
				<ul>
					<li><a href="javascript:;"><span>客户管理数量历史查询</span></a></li>
					<li><a href="javascript:;"><span>客户管理能力历史查询</span></a></li>
					<li><a href="javascript:;"><span>客户管理效果历史查询</span></a></li>
				</ul>
			</div>
		</div>
		<div class="tabsContent" >
            <div>
			@Html.Partial("../Chart/Line", ChartModel)
            @Html.Partial("../Chart/Line", ChartModel1)
            @Html.Partial("../Chart/Line", ChartModel3)
            </div>
            <div>
			@Html.Partial("../Chart/Line", ChartModelT2)
            @Html.Partial("../Chart/Line", ChartModel1T2)
            @Html.Partial("../Chart/Line", ChartModel3T2)
            </div>
            <div>
			@Html.Partial("../Chart/Line", ChartModelT3)
            @Html.Partial("../Chart/Line", ChartModel1T3)
            @Html.Partial("../Chart/Line", ChartModel3T3)
            </div>
		</div>
		<div class="tabsFooter">
			<div class="tabsFooterContent"></div>
		</div>
	</div>
</div>

</div>
}
